package com.coffee.socketio;

import com.coffee.socketio.command.CommandEnum;
import com.coffee.socketio.handler.HandlerMapping;
import com.coffee.socketio.handler.SocketioCloseHandler;
import com.coffee.socketio.handler.SocketioConnectHandler;
import com.coffee.socketio.handler.SocketioUserValidHandler;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * @author: songkui
 * @since: 2023/2/23 10:30
 */
@Slf4j
@NoArgsConstructor
public class CoffeeSocketioBuilder {

    public static CoffeeSocketioBuilder builder(){
        return new CoffeeSocketioBuilder();
    }


    public CoffeeSocketioBuilder socketConnectHandler(SocketioConnectHandler connectHandler) {
        HandlerMapping.initializeSocketConnectHandler(connectHandler);
        return this;
    }

    public CoffeeSocketioBuilder socketCloseHandler(SocketioCloseHandler closeHandler) {
        HandlerMapping.initializeSocketClosetHandler(closeHandler);
        return this;
    }

    public CoffeeSocketioBuilder socketUserValidHandler(SocketioUserValidHandler userValidHandler) {
        HandlerMapping.initializeSocketUserValidHandler(userValidHandler);
        return this;
    }



    public CoffeeSocketioBuilder initHandler(Map<Integer, CommandEnum> commandEnumMap, String handlerPackagePath) throws Exception {
        SocketioInitialize.initializeCommandModel(commandEnumMap);
        SocketioInitialize.initializeHandlerMapping(handlerPackagePath, commandEnumMap);
        return this;
    }

    public void start(Integer port, String host) {
        SocketioServer socketServer = new SocketioServer();
        socketServer.start(port, host);
    }


}
